﻿#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<unordered_set>
#include<set>
#include<unordered_map>
#include<map>
using namespace std;
void test1() {
	unordered_set<int> s;
	int a[] = { 3,6,2,1,8,9,0,4 };
	for (auto& num : a) {
		s.insert(num);
	}
	unordered_set<int>::iterator it = s.begin();
	while (it != s.end()) {
		cout << *it <<" ";  //无序的
		++it;
	}
	cout << endl;

	cout << *s.find(8) << endl;
}
void test2() {  //set和unordered_set的效率比较
	unordered_set<int> us;
	set<int> s;
	vector<int> v;
	const int N = 100000;
	srand(time(0));
	for (int i = 0; i < N; i++) {
		v.push_back(rand() + i);
	}
	size_t time1 = clock();
	for (auto& num : v) {
		s.insert(num);
	}
	size_t time2 = clock();
	cout << "set的插入：" << time2 - time1 << endl;
	size_t time11 = clock();
	for (auto& num : v) {
		us.insert(num);
	}
	size_t time22 = clock();
	cout << "unordered_set的插入：" << time22 - time11 << endl;
	size_t time3 = clock();
	for (auto& num : v) {
		s.find(num);
	}
	size_t time4 = clock();
	cout << "set的查找：" << time4 - time3 << endl;
	size_t time33 = clock();
	for (auto& num : v) {
		us.find(num);
	}
	size_t time44 = clock();
	cout << "unordered_set的查找：" << time44 - time33  << endl;
	cout << "插入数据个数：" << s.size() << endl;
	cout << "插入数据个数：" << us.size() << endl << endl;
	
	size_t time5 = clock();
	for (auto e : v)
	{
		s.erase(e);
	}
	size_t time6 = clock();
	cout << "set的删除:" << time6 - time5 << endl;
	size_t time55 = clock();
	for (auto e : v)
	{
		us.erase(e);
	}
	size_t time66 = clock();
	cout << "unordered_set的删除:" << time66 - time55 << endl;
}

void test3() {
	unordered_map<string, string> m;
	m.insert({ "dog", "狗" });
	m.insert({"cat", "猫"});
	m.insert({ "sheep", "羊" });
	m.insert({ "pig", "猪" });
	m.insert({ "dragon", "龙" });
	m.insert({ "bird", "鸟" });

	for (auto& num : m) {  //也是无序的
		cout << num.first << "：" << num.second << endl;
	}

}
 int main() {
	test3();

	return 0;
}